from collections import defaultdict


class Event:

    def __init__(self, line: str) -> "Event":
        self.user, date, time, success = line.strip().split(' ')
        day, month = (int(x) for x in date.split('/'))
        hours, mins = (int(x) for x in time.split(':'))
        self.timestamp = (((month * 30) + day) * 24 + hours) * 60 + mins
        self.failed = (success == "[failure]")

    def __repr__(self) -> str:
        return f'(Event: {self.user} {self.timestamp} {self.failed})'

    def __gt__(self, other: "Event") -> bool:
        return self.timestamp > other.timestamp


S, N = (int(x) for x in input().split(' '))

failed_logins = defaultdict(list)
for _ in range(S):
    event = Event(input())
    if event.failed:
        failed_logins[event.user].append(event)

for user in failed_logins:
    failed_logins[user].sort()

targets = set()
for user, events in failed_logins.items():
    for i in range(len(events) - 2):
        if events[i + 2].timestamp - events[i].timestamp < 10:
            targets.add(user)

print(' '.join(sorted(targets)))
